package jd.client.util;

import jd.client.exception.ResponseParseException;

/**
 * @author Denis Migol
 * 
 */
public final class Parser {
	/**
	 * Don't let anyone instantiate this class.
	 */
	private Parser() {
	}

	/**
	 * 
	 * @param string
	 * @return
	 * @throws ResponseParseException
	 */
	public static Integer parseCount(final String string) throws ResponseParseException {
		final String s;
		try {
			s = string.trim();
		} catch (final Exception e) {
			throw new ResponseParseException("Couldn't parse count: " + string, e);
		}
		try {
			return Integer.parseInt(s);
		} catch (final Exception e) {
			throw new ResponseParseException("Couldn't parse count: " + s, e);
		}
	}

	/**
	 * 
	 * @param string
	 * @return
	 * @throws ResponseParseException
	 */
	public static Boolean parseBoolean(final String string) throws ResponseParseException {
		final String s;
		try {
			s = string.trim();
		} catch (final Exception e) {
			throw new ResponseParseException("Couldn't parse Boolean: " + string, e);
		}
		try {
			return Boolean.parseBoolean(s);
		} catch (final Exception e) {
			throw new ResponseParseException("Couldn't parse Boolean: " + s, e);
		}
	}
}
